package com.autumn.platform.dao.schema.script.original;

import java.util.List;

import org.apache.ibatis.parsing.XNode;
import org.apache.ibatis.scripting.xmltags.MixedSqlNode;
import org.apache.ibatis.scripting.xmltags.SqlNode;
import org.apache.ibatis.scripting.xmltags.TrimSqlNode;
import org.apache.ibatis.session.Configuration;

import com.autumn.platform.dao.schema.script.ScriptHandlerSupport;

public class TrimScriptHandler extends ScriptHandlerSupport {

    @Override
    public void handleScriptNode(Configuration configuration, XNode node, List<SqlNode> targetContents) {
        List<SqlNode> contents = parseDynamicTags(configuration, node);
        MixedSqlNode mixedSqlNode = new MixedSqlNode(contents);
        String prefix = node.getStringAttribute("prefix");
        String prefixOverrides = node.getStringAttribute("prefixOverrides");
        String suffix = node.getStringAttribute("suffix");
        String suffixOverrides = node.getStringAttribute("suffixOverrides");
        TrimSqlNode trim = new TrimSqlNode(configuration, mixedSqlNode, prefix, prefixOverrides, suffix,
                suffixOverrides);
        targetContents.add(trim);
    }
}
